3D Graphics Programming with QuickDraw 3D 1.5.4
Previous | QD3D Book | Overview | Chapter Contents | Next |
The remaining step before you can create a view is to create a camera object. A camera object specifies a point of view and a method of projecting the three-dimensional model into two dimensions. Listing 8 illustrates how to create a camera. See the chapter "Camera Objects" for complete details on the routines called in MyNewCamera .
TQ3CameraObject MyNewCamera (void)
{
TQ3CameraObject myCamera;
TQ3CameraData myCameraData;
TQ3ViewAngleAspectCameraData myViewAngleCameraData;
TQ3Point3D cameraFrom = { 0.0, 0.0, 15.0 };
TQ3Point3D cameraTo = { 0.0, 0.0, 0.0 };
TQ3Vector3D cameraUp = { 0.0, 1.0, 0.0 };
/*Fill in camera data.*/
myCameraData.placement.cameraLocation = cameraFrom;
myCameraData.placement.pointOfInterest = cameraTo;
myCameraData.placement.upVector = cameraUp;
myCameraData.range.hither = .1;
myCameraData.range.yon = 15.0;
myCameraData.viewPort.origin.x = -1.0;
myCameraData.viewPort.origin.y = 1.0;
myCameraData.viewPort.width = 2.0;
myCameraData.viewPort.height = 2.0;
myViewAngleCameraData.cameraData = myCameraData;
myViewAngleCameraData.fov = Q3Math_DegreesToRadians(100.0);
myViewAngleCameraData.aspectRatioXToY = 1;
myCamera = Q3ViewAngleAspectCamera_New(&myViewAngleCameraData);
/*Return a camera.*/
return (myCamera);
}
Like before, the MyNewCamera function simply fills out the fields of the appropriate data structures and calls the Q3ViewAngleAspectCamera_New function to create a new camera object.
All angles in QuickDraw 3D are specified in radians. You can use the Q3Math_DegreesToRadians macro to convert degrees to radians. This is illustrated in Listing 8 , which sets the fov field to 100 degrees.
Previous | QD3D Book | Overview | Chapter Contents | Next |